<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>定额红包</title>
 
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.validate.min.js"></script>	
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>

    <style type="text/css">
       .wrapper{
       	padding:20px;
		margin-left: 270px;
       }    
       .lt{
       	float:left;
       }
       .rt{
       	float:right;
       }
       .panel{
       		padding: 20px 20px 20px 40px;
			margin-top: 100px;
       }
       .clearfix{
       		overflow:hidden;
       }
       .left_box{
       		width:50%;
       }
       .right_box{
       		width:400px;
       		text-align:center;
			padding-top:10px;
       }
	.txt{
		color:#333;
		font-size:16px;
		width:100px;
		text-align:right;
		padding-right:20px;
		height:34px;
		line-height:34px;
	}
	 input{
	   display:inline-block;
	   height:30px;
	   width:320px;
	   *+width:280px;
	   border:none;
	   padding:0 10px;
	   text-align:right;
	   outline:none;
	}
	.titles{
		font-size:20px;
		*+font-size:18px;
		color:#333;
		overflow:hidden;
		width:100%;
		padding:5px 20px;
		background:#f8f8f8;
	}
	.titles .span1{
		float: left;
	}
	.titles .span2{
		float:right;
	}
	.wraper .btn-info{
		background:#228ded;
		border-color:#228ded;
		width:155px;
		height:36px;
		font-size:20px !important;
		line-height:18px;
		*+line-height:15px;
		outline:none;	
	}
	.box{
		width: 450px;
		margin:10px 0;
		
	}
	input[type="button"]{
		background:#fff;
	}
	.box label{
	   border:1px solid #ccc;
	   border-radius:2px;
	   padding:2px;
       line-height: 28px;
       width:350px;
       *+width:318px;
	   font-weight:500;
	   font-size:16px;
	  
	}
	.pic_box{
		width:398px;
		height:304px;
	}
	.error{
		text-align:right;
		font-size: 14px;
	}
	.btn_pic{
		background:#4bc5c3;
		color:#fff;width: 80px;
		height:28px;
		line-height:28px;
		border:1px solid #1aa3a5;
		border-radius:4px;
		
	}
	.pic_box {
		margin-bottom: 20px;
	}
	.box label input{
		font-size:16px !important;
	}
    </style>
</head>
<body>
<jsp:include page="../../top.jsp"></jsp:include>
<div class="wrapper">
     <div class="panel panel-default clearfix" style="box-size:border-box;padding-top:30px;padding-bottom:100px;padding-right:150px; width:1200px;">
          <div class="left_box lt">
          	<form action="" id="redEnvForm">
          	<input type="hidden" id="isAllday"  name="isAllday" value=""/>
          	<input type="hidden" id="isSendAll"  name="isSendAll" value="0"/>
          	<input type="hidden" id="agentCodes"  name="agentCodes" value=""/>
          	<input type="hidden" id="communityIds"  name="communityIds" value=""/>
          	<input type="hidden" id="buildingIds"  name="buildingIds" value=""/>
          	<input type="hidden" id="unitIds"  name="unitIds" value=""/>
          	<input type="hidden" id="roomIds"  name="roomIds" value=""/>          	
          	<input type="hidden" id="mainReType"  name="mainReType" value="1"/>  
          	<input type="hidden" id="adPicture"  name="adPicture" value=""/>          	
          	        	
        	
			 	<div class="clearfix box">
			 		<div class="lt txt">红包名称：</div><label><input type="text" id="rName" name="rName" class="lt"  placeholder="请输入红包名称" style="padding: 0px;width: 336px;*+width:320px;"/></label>
			 	</div>
			 	<div class="clearfix box">
			 		<div class="lt txt">单个金额：</div><label><input type="text" id="Amount" name="Amount" class="lt"
				onkeyup="num(this)" onafterpaste="num(this)" placeholder="0.00"/>元</label>
			 	</div>
			 	<div class="clearfix box">
			 		<div class="lt txt">红包个数：</div><label><input type="text" id="totalNum" name="totalNum" class="lt"  placeholder="请输入红包个数"/>个</label>
			 	</div>
			 	
			 	<div class="clearfix box">
			 		<div class="lt txt">发送对象：</div>
  					  <label style="position: relative;"><input type="button" id="sendObject" name="sendObject" onclick="setSendList()" value="请选择发送对象" style="padding-right:0;"><img style="position: absolute;top: 8px;left: 325px;*+left:302px;" src="${pageContext.request.contextPath}/static/images/admin/wallet/arrow_rt.jpg"/></label>
			 	</div>
			 	<div class="clearfix box">
			 		<div class="lt txt">限领次数：</div><label><input type="text" id="reTimes" name="reTimes" class="lt" placeholder="请输入红包每人可领取次数"/>次</label>
			 	</div>
			 	<div class="clearfix box">
			 		<div class="lt txt">有效期限：</div><label><input type="text" id="effectiveDate" name="effectiveDate" class="lt" placeholder="请输入红包发放的有效期，如：1-7"/>天</label>
			 	</div>
			 	<div class="clearfix box">
			 		<div class="lt txt">发放时间：</div><label style="position:relative;"><input type="text" id="period" name="period" class="lt" placeholder="请选择红包发放的时间" onclick="setTime()" /><img src="${pageContext.request.contextPath}/static/images/admin/wallet/time.jpg" class="rt" style="position:absolute;top:8px;right:4px;"></label>
			 	</div>
			 	<input type="button" class="btn btn-info" value="塞钱进红包" onclick="addQuota()" style="margin-left:200px;height:34px;font-size: 16px !important;margin-top:20px; width:110px;background:#2e8ded !important;border-color:#2e8ded !important;"/>
			 	<input type="button" class="btn btn-info" value="取消" onclick="closeWin()" style="margin-left:10px;margin-top:20px;font-size: 16px !important;height:34px; width:80px;background:#f9f9f9 !important;border-color:#dddddd !important;color:#666 !important;"/>
          </div>   
          <div class="right_box rt">
          	<div class="pic_box">
          		<img id="adpic" src="${pageContext.request.contextPath}/static/images/admin/wallet/dehb_03.jpg"/>
          	</div>
                <div class="input-group" style="width:54px;margin-left:40%">
                    <div class="upload" style="background:#fff !important;border-radius:4px;">
                        <input class="form-control" id="upload" type="file" name="upload" onchange="uploadfile()"
                               style="position: absolute;width: 60px;opacity: 0;border-radius:4px;"/>
                        <div class="btn_pic">上传图片</div>
                    </div>
                </div>          	
		<div style="width:100%;font-size:16px !important; text-align:left;margin-top:20px;">添加图片链接：<input type="url" id="cRul" name ="cUrl" style="border:1px solid #ccc;border-radius:2px; width:280px;text-align:left;line-height:24px;"/></div>
          </div>   
          	 	</form>          
     </div>
 </div>
 <script type="text/javascript">
function num(obj){
obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
}
$(function(){
jQuery.validator.setDefaults({
    debug: true,
    errorElement: 'div',
    errorPlacement: function(error, element) {
            error.insertAfter(element.parent());
    }
});
$("#redEnvForm").validate({
    rules: {
      rName: {
	  required:true,
	  maxlength:8
	  },
	  Amount:{
	  required:true,
	  number:true,
	  min:0.01,
	  max:9999
	  },
	  totalNum:{
	  required:true,
	  digits:true,
	  min:1,
	  max:9999
	  },
	  sendObject:{
	  required:true
	  },
	  reTimes:{
	  required:true,
	  digits:true,
	  min:1,
	  max:99
	  },
	  effectiveDate:{
	  required:true,
	  digits:true,
	  min:1,
	  max:7
	  },
	  period:{
	  required:true
	  }
	  }
})
});
 function uploadfile(){
	 	var formData = new FormData($( "#redEnvForm" )[0]); 
    	$.ajax({  
         url: '${pageContext.request.contextPath}/admin/redPacket_uploadFile.action',  
         type: 'POST',  
		 data: formData,  
         async: false,  
         cache: false,	 
         contentType: false,  
         processData: false,  
         success: function (result) {  
              result = JSON.parse(result)
              if (result.code == 1) {
            	  	var fileUrl = result.fileUrl;
					$("#adpic").attr('width',"398px");
					$("#adpic").attr('height',"304px");					
					$("#adpic").attr('src',fileUrl);
					$("#adPicture").val(fileUrl);
              }else{
            	  layer.alert(result.msg);
              }
         },  
         error: function (returndata) {  
        	 layer.alert(returndata);  
         }  
    	});
	}
 function setTime(){
	var oldTime = $('#period').val();
	if(oldTime=="默认全天候"){
		oldTime = "1";
	}else{
		oldTime = oldTime.replace('和','and');
	}
 	layer.open({
        type: 2,
        title: ['设置发放时间', 'font-weight:bold'],
        shadeClose: true, //点击遮罩关闭层
        area: ['550px', '360px'],
        scrollbar: false,
        content: '${pageContext.request.contextPath}/admin/redPacket_setTime.action?period='+oldTime,
        btn: ['确定','取消'],
        yes:function(index,layero){
            var iframeWin = window[layero.find('iframe')[0]['name']];
			iframeWin.getTime();

        },
        cancel: function (index, layero) {
            layer.close(index);
        }
    });
 	}
 
 function setSendList(){
	 	layer.open({
	        type: 2,
	        title: ['设置发送对象', 'font-weight:bold'],
	        shadeClose: true, //点击遮罩关闭层
	        area: ['1100px', '750px'],
	        scrollbar: false,
	        content: '${pageContext.request.contextPath}/admin/redPacket_setSendList.action'
	    });
	 	}
	function reValidate(elementName){
		    $("#redEnvForm").validate().element($(elementName));
			var rs = $(elementName).valid();
		}
	function addQuota(){
	    $("#redEnvForm").validate();
		if(!$("#redEnvForm").valid()){
			return false;
		}
		var formData = new FormData($( "#redEnvForm" )[0]); 
    	$.ajax({  
         url: '${pageContext.request.contextPath}/admin/redPacket_addRedEnv.action',  
         type: 'POST',  
         data: formData,  
         async: false,  
         cache: false,  
         contentType: false,  
         processData: false,  
         success: function (result) {  
              result = JSON.parse(result)
              if (result.code == 1) {
            	  	var orderId = result.orderId;
            	  	layer.open({
            	         type: 2,
            	         //title: ['支付', 'font-weight:bold'],
            	         title:false,
						 closeBtn: 0,	
            	         shadeClose: true, //点击遮罩关闭层
            	         area: ['540px', '440px'],
            	         scrollbar: false,
            	         content: '${pageContext.request.contextPath}/admin/userWallet_payOrderView.action?orderId='+orderId
            	     });

                  	//layer.alert(result.msg,function(){
              		//parent.layer.closeAll();	  
                  	//});
              }else{
            	  layer.alert(result.msg);
              }
         },  
         error: function (returndata) {  
        	 layer.alert(returndata);  
         }  
    	});
    }
	function closeWin(){
		window.location.href="${pageContext.request.contextPath}/admin/redPacket_redEnvlistView.action"; 
	}
 </script>
</body>
</html>
